package com.acme.bankapp.domain.account;



public class CheckingAccount extends AbstractAccount {

	final private double overdraft;
	private double overdraftcurrent;

	@Override
	public double maximumAmountToWithdraw() {
		return super.maximumAmountToWithdraw() + overdraft;
	}

	public CheckingAccount(double bal, double ovd) {
		super(bal);
		overdraft = ovd;
		overdraftcurrent = ovd;
	}

	public void withdraw(double x) {
		if (x < 0) {
			return;
		}
		if (x <= balance) {
			balance -= x;
			return;
		}
		if ((overdraftcurrent + balance) >= x) {
			x -= balance;
			balance = 0;
			overdraftcurrent -= x;
		}
	}

	@Override
	public void deposit(double x) {
		if (x < 0) {
			return;
		}
		if (overdraftcurrent < overdraft) {
			overdraftcurrent += x;
			if (overdraftcurrent > overdraft)
				balance += overdraftcurrent - overdraft;
		} else {
			balance += x;
		}
	}
}
